import unittest
from gamestate import *


class GamestateTest(unittest.TestCase):
    def setUp(self):
        self.players_list = [i for i in range(8)]
        self.donor = dict()
        self.recipient = dict()
        for player in self.players_list:
            self.donor[player] = 0
            self.recipient[player] = 0
        self.round_cnt = 100

    def test_get_next_pair_traditional_strategy(self):
        """Test get_next_pair in TraditionalStrategy
        """
        self.strategy = TraditionalStrategy(self.players_list)

    def test_get_next_pair_odd_strategy(self):
        """Test get_next_pair in OddStrategy
        """
        self.strategy = OddStrategy(self.players_list)

    def tearDown(self):
        for round_num in range(self.round_cnt):
            players = self.strategy.get_next_pair()
            self.donor[players[0]] += 1
            self.recipient[players[1]] += 1

            min_value = self.round_cnt
            max_value = 0
            for player in self.players_list:
                min_value = min(min_value, self.donor[player])
                max_value = max(max_value, self.donor[player])
                min_value = min(min_value, self.recipient[player])
                max_value = max(max_value, self.recipient[player])

                self.assertTrue(max_value - min_value <= 1)

            pref_players = players
        self.strategy = None


if __name__ == "__main__":
    unittest.main()
